<template>
  <div class="index-container">
    <!-- 金牌课程 -->
    <van-tabs :swipe-threshold="1" v-model="active" sticky swipeable @change="fetchList">
      <van-tab v-for="(itme, index) in groupsList" :key="index" :title="itme.name">
        <div class="mt10">
          <van-list
            :loading="loading"
            :finished="finished"
            finished-text="暂时没有更多了哦~"
            @load="onLoad"
          >
            <van-grid :gutter="15" :border="false" :column-num="2">
              <van-grid-item
                v-for="(item, index) in List"
                :key="index"
                @click="topackDetails1(item)"
              >
                <van-image width="100%" height="105" :src="item.cover" />
                <div class="content">
                  <h3 class="title">{{ item.name }}</h3>
                  <div class="jiage">
                    抢购价:
                    <span>
                      <i>¥</i>
                      <i style="font-size: 18px">{{ item.price }}</i>
                    </span>
                  </div>
                  <div class="xuexi">{{ item.init_sale_num }}人已学习</div>
                </div>
              </van-grid-item>
            </van-grid>
          </van-list>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
import { getGoodsGroups, getGoodsLists } from '@/api/goods/pack'
export default {
  data() {
    return {
      active: 0,
      queryParams: {
        group_id: null,
        cate_id: null,
        type: 'pack',
        page: 1,
        size: 10
      },
      groupsList: [],
      List: [],
      loading: false,
      finished: false
    }
  },

  computed: {},

  mounted() {
    this.queryParams.cate_id = this.$route.query.subject_id || 2
    this.goodsGroups()
  },

  methods: {
    // 初始化数据
    fetchList() {
      this.queryParams.group_id = this.groupsList[this.active].id
      this.List = []
      this.finished = false
      this.queryParams.page = 1
      this.onLoad()
    },
    async onLoad() {
      this.loading = true
      await getGoodsLists(this.queryParams).then(res => {
        this.List = this.List.concat(res.data)
        this.queryParams.page = this.queryParams.page + 1
        if (res.data.length < 10) {
          this.finished = true
        }
      })
      this.loading = false
    },
    goodsGroups() {
      getGoodsGroups(this.queryParams).then(res => {
        console.log(res)
        this.groupsList = res.data
        this.groupsList.unshift({ name: '全部', id: null })
      })
    },
    topackDetails1(row) {
      const data = {
        id: row.id
        // token: this.share_token
      }
      this.$router.push({ path: '/pack-details', query: data })
    }
  }
}
</script>

<style lang="scss" scoped>
.index-container {
  background: #ffffff;
  ::v-deep .van-grid {
    margin-top: 20px;
    .van-grid-item {
      box-shadow: 0px 1.5px 4px 0px rgba(210, 212, 213, 0.2);
      border-radius: 5px;
    }
    .van-grid-item__content {
      box-shadow: 0px 1px 4px 0px rgba(210, 212, 213, 0.2);
      border-radius: 5px;
      padding: 0;
      overflow: hidden;
    }
    .content {
      box-sizing: border-box;
      width: 100%;
      padding: 8px 10px 10px;
      .title {
        font-size: 14px;
        font-weight: 600;
        color: #333333;
        line-height: 21px;
        @include textoverflow(1);
      }
      .jiage {
        font-size: 12px;
        color: #009697;
        line-height: 30px;
      }
      .xuexi {
        display: table;
        // margin-top: 10px;
        min-width: 75px;
        padding: 0 5px;
        height: 20px;
        line-height: 20px;
        font-size: 12px;
        color: #11a8a4;
        background: rgba(7, 120, 121, 0.1);
        border-radius: 2px;
      }
      .van-button {
        width: 27px;
        height: 14px;
        background: #fd953f;
        padding: 0;
        vertical-align: bottom;
        .van-button__text {
          font-size: 14px;
          font-weight: bold;
          color: #fffefe;
        }
      }
      .open_price {
        font-size: 9px;
        font-weight: 800;
        color: #009697;
        // line-height: 30px;
      }
      .open_number {
        margin-left: 4px;
        line-height: 14px;
        font-size: 6px;
        font-weight: 500;
        text-decoration: line-through;
        color: #999999;
      }
    }
  }
}
</style>
